/*
    Contact info:
    bhepple@freeshell.org
    http://bhepple.freeshell.org/scrmgr

    Copyright (C) 1991-2008 Bob Hepple

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; see the file COPYING.  If not, write to
    the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
    Boston, MA 02111-1307, USA.

*/
#include <getopt.h>
#include <setjmp.h>

#include "smlib.h"

CHAR *smconv_rcsid(void) {
    return("$Id: smconv.c,v 1.7 2008/02/19 13:15:50 bhepple Exp $");
}

extern int	errno;

static CHAR	rev_string[] = "$Revision: 1.7 $";
jmp_buf		NoMoreHeap;

static CHAR *usage_msg[] = {
"Reads old SCRMGR files and outputs new format on stdout.",
"Old scrmgr files usually have the '.dat'.",
NULL
};

void usage()
{
    CHAR **c;
    
    fprintf(stderr, "Revision %s of %s.\n", rev_string, sm_program_name);
    fprintf(stderr, "Usage: %s scrmgr-file\n", sm_program_name);
    
    c = usage_msg;
    while (*c) {
        fputs(*c, stderr);
        fputc('\n', stderr);
        c++;
    }
    exit(2);
}

int main(argc, argv)
    int		argc;
    CHAR	**argv;
{
    int		c,
    		errors = 0;
    CHAR	*filename, *p;

    sm_pre_init(argc, argv);

    while ((c = getopt(argc, argv, "?")) != EOF)
        switch (c) {
        case '?':
        default:
            usage();
            break;
        }

    if (setjmp(NoMoreHeap)) {
	fprintf(stderr, "Ran out of heap!\n");
	exit(1);
    }

    sm_init(0, argc, argv);
    /*smio_term();*/

    if (optind >= argc)
	usage();
    else
        for (; optind < argc; optind++) {
	    sm_clear_out(0);
	    filename = argv[optind];
            if (sm_fopen(sm_user_screens(), filename) == SM_ERROR)
		usage();
	    sm_fwrite(sm_user_screens(), stdout);
	}

    exit(errors);
}


/* For emacs:
 * Local Variables:
 * tab-width: 8
 * End:
 */
